package com.controller;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.entity.Cart;
import com.entity.Favorite;
import com.pojo.Favorites;
import com.service.FavoriteService;
import com.service.UserService;
import com.service.impl.FavoriteServiceImpl;

import java.util.List;

import javax.annotation.Resource;

/**
 * @program: ssm
 * @description: 鏀惰棌澶�
 * @author: zl
 * @create: 2022-05-17 21:23
 **/


@RequestMapping("/favorite")
@Controller
public class FavoriteController {

    @Autowired
    @Qualifier("favorite")
    private FavoriteServiceImpl favoriteService;

    @Resource(name = "userSer") // 此处与UserServiceImpl的名称匹配
	private UserService userService;
    
    @RequestMapping("/all")
    public String select(Model model, Integer userid){
        List<Favorites> favorites = favoriteService.selectALl(userid);
        System.out.println(favorites+"jjjj"+userid+"]]]]]]]");
        model.addAttribute("favorites",favorites);
        return "favorite";
    }

    @RequestMapping("/del")
    public String delete( Model model, Integer fid,Integer userid){
        favoriteService.deleteFavorite(fid);
        //List<Favorites> favorites = favoriteService.selectALl(userid);
        model.addAttribute("userinf",userService.selectUserById(userid));
        model.addAttribute("href",5);
        return "userManage";
    }
    
    @ResponseBody
    @RequestMapping("/add")
    public String add(Favorite favorite){
        favoriteService.addFavorite(favorite);
        return "收藏商品成功！请前往收藏夹查看";
    }
}
